package hu.uniobuda.nik.bsik2f.GPSDemo;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class MyActivity extends Activity {
    private TextView longitude;
    private TextView latitude;
    private LocationManager locManager;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        longitude = (TextView) findViewById(R.id.textLongitude);
        latitude = (TextView) findViewById(R.id.textLatitude);

        locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();

        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 50, locationListener); //3sec vagy 50m

    }

    private LocationListener locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            latitude.setText(String.valueOf(location.getLatitude()));
            longitude.setText(String.valueOf(location.getLongitude()));
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {
        }

        @Override
        public void onProviderEnabled(String s) {
        }

        @Override
        public void onProviderDisabled(String s) {
        }
    };

    @Override
    protected void onPause() {
        super.onPause();
        locManager.removeUpdates(locationListener);
    }
}
